package com.example.book_test.enums;

public enum BookStatusEnum {
    DELETED(0, "删除"),
    NORMAL(1, "可借阅"),
    FORBINNEN(2, "不可借阅");
    /**
     * 状态，对应了BookInfo里的status
     */
    private int code;
    /**
     * 状态对应的中文，对应了BookInfo里的statusCN
     */
    private String name;

    BookStatusEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    /**
     * 根据 code获取对应的 BookStatusEnum
     * 使用static，这样就不需要调用时专门去new一个对象了
     * @return
     */
    public static BookStatusEnum getNameByCode(int code){
        switch (code){
            case 0: return BookStatusEnum.DELETED;
            case 1: return BookStatusEnum.NORMAL;
            case 2: return BookStatusEnum.FORBINNEN;
            default:
                return BookStatusEnum.FORBINNEN;
        }
    }
}
